


export class navigationTools
{
    constructor(page)
    {
        this.page = page ;
    }

    async urlNavigator({url})
    {
        await this.page.ref.goto(url);
        return `Navigated to ${url}`;
    }

    async currentURL({})
    {
        return this.page.ref.url().slice(0,50);
    }

    async goBack({})
    {
        try
        {
            const response = await this.page.ref.goBack({timeout : 4000});
            if(response) return `successfully went back: ${response.url()}`;
            else return "go back returned null; - no history entry";

        }
        catch(error)
        {
            return `failed to go back: ${error}`;
        }
    }

    async scroll({}, numPages = 0.8)
    {
        await this.page.ref.evaluate(({numPages}) => 
        {
            window.scrollBy(0, numPages * window.innerHeight);
        },{numPages});
        return `scrolled down by ${numPages}` ;
    }
}